

import cv2
import numpy as np
import argparse
import copy
import os
import pdb
#pdb.set_trace()
import time

def parse_args():
    parser = argparse.ArgumentParser(description='Calculate adjointing video frame similarity.')
    parser.add_argument('--video-path', type=str, default='', help='path for video')
    parser.add_argument('--save-video', type=str, default='',help='path for save part video')
    args = parser.parse_args()
    return args

def pull_frame(video_path, save_path, interval, start_index):
    ## parse parameter
    ##video_path = args.video_path
    ##interval = args.interval
    ##save_path = args.save_path
    ##frame_num_total = args.frame_num
    ##
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    
    ## video 
    if not os.path.exists(video_path):
        print('Path:{} is empty.'.format(video_path))
        return 
    video_capture = cv2.VideoCapture(video_path)
    #frame_num = int(video_capture.get(7))
    frame_index = 0
    total_num = 0
    while True:
        #if frame_index>=frame_num:
        #    break
        ret, frame = video_capture.read()
        if not ret:
            break

        frame_index += 1
        

        if frame_index%interval==1:
            cv2.imwrite(os.path.join(save_path,str(start_index)+'.jpg'), frame)
            print(" {}/{} ".format(frame_index, frame_num))
            total_num += 1
            start_index += 1
            
            
    print('Frames total num:{}', total_num)

# coding: utf-8
import os
import os.path
 
def get_files_list(dir):
    '''
    实现遍历dir目录下,所有文件(包含子文件夹的文件)
    :param dir:指定文件夹目录
    :return:包含所有文件的列表->list
    '''
    # parent:父目录, filenames:该目录下所有文件夹,filenames:该目录下的文件名
    files_list=[]
    for parent, dirnames, filenames in os.walk(dir):
        for filename in filenames:
            # print("parent is: " + parent)
            # print("filename is: " + filename)
            # print(os.path.join(parent, filename))  # 输出rootdir路径下所有文件（包含子文件）信息
            files_list.append([os.path.join(parent, filename)])
    return files_list

def rename_file(dir):
    rootdir = dir
    i=0;
    for parent, dirnames, filenames in os.walk(rootdir):
        for filename in filenames:
            # print("parent is: " + parent)
            # print("filename is: " + filename)
            print(os.path.join(parent, filename))  # 输出rootdir路径下所有文件（包含子文件）信息
            newName=str(i)+".jpg"
            os.rename(os.path.join(parent, filename), os.path.join(parent, newName))
            i=i+1


if __name__=='__main__':
    dir = 'images'
    files_list=get_files_list(dir)
    print(files_list)

def main():
    print('Hello World!')
    rename_file('D:\\videos\\3')
    #pull_frame('D:\\videos\\1.mp4', 'D:\\frames', 10, 1)
    #args = parse_args()
    #print(args)
    #save_part_video(args)
    #process_video(args)
    #pull_frame(args)
    #det_num, filter_num = process_imglist_sta(args)
    #print('det_num = {}, filter_num = {}'.format(det_num, filter_num))
    #process_imglist(args)

if __name__=="__main__":
    main()
